// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   check_ok.java

package logistics.product_providers;

import include.nseer_cookie.counter;
import include.nseer_cookie.exchange;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataTag;

public class check_ok extends HttpServlet
{

	public check_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			nseer_db_backup1 logistics_db = new nseer_db_backup1(dbApplication);
			if (logistics_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				counter count = new counter(dbApplication);
				ValidataTag vt = new ValidataTag();
				String product_logistics_recommend_ID = request.getParameter("product_logistics_recommend_ID");
				String config_id = request.getParameter("config_id");
				String recommender = request.getParameter("recommender");
				String bodyc = new String(request.getParameter("recommend_describe").getBytes("UTF-8"), "UTF-8");
				String recommend_describe = exchange.toHtml(bodyc);
				String check_time = request.getParameter("check_time");
				String checker = request.getParameter("checker");
				String checker_ID = request.getParameter("checker_ID");
				String product_name = request.getParameter("product_name");
				String product_ID = request.getParameter("product_ID");
				String provider_amount = request.getParameter("provider_amount");
				String sql6 = (new StringBuilder("select id from logistics_workflow where object_ID='")).append(product_logistics_recommend_ID).append("' and ((check_tag='0' and config_id<'").append(config_id).append("') or (check_tag='1' and config_id='").append(config_id).append("'))").toString();
				ResultSet rs6 = logistics_db.executeQuery(sql6);
				if (!rs6.next())
				{
					if (vt.validata((String)dbSession.getAttribute("unit_db_name"), "logistics_product_providers_recommend", "product_logistics_recommend_ID", product_logistics_recommend_ID, "check_tag").equals("0"))
					{
						try
						{
							String sql = (new StringBuilder("update logistics_product_providers_recommend set check_time='")).append(check_time).append("',checker='").append(checker).append("',recommender='").append(recommender).append("',recommend_describe='").append(recommend_describe).append("',change_tag='0' where product_logistics_recommend_ID='").append(product_logistics_recommend_ID).append("'").toString();
							logistics_db.executeUpdate(sql);
							String sql9 = (new StringBuilder("update logistics_workflow set checker='")).append(checker).append("',checker_ID='").append(checker_ID).append("',check_time='").append(check_time).append("',check_tag='1' where object_ID='").append(product_logistics_recommend_ID).append("' and config_id='").append(config_id).append("'").toString();
							logistics_db.executeUpdate(sql9);
							sql9 = (new StringBuilder("select id from logistics_workflow where object_ID='")).append(product_logistics_recommend_ID).append("' and check_tag='0'").toString();
							ResultSet rset = logistics_db.executeQuery(sql9);
							if (!rset.next())
							{
								sql9 = (new StringBuilder("update logistics_product_providers_recommend set check_tag='1' where product_logistics_recommend_ID='")).append(product_logistics_recommend_ID).append("'").toString();
								logistics_db.executeUpdate(sql9);
								String provider_group = "";
								for (int i = 1; i <= Integer.parseInt(provider_amount); i++)
								{
									String tem_provider_ID = (new StringBuilder("provider_ID")).append(i).toString();
									String provider_ID = request.getParameter(tem_provider_ID);
									String tem_provider_name = (new StringBuilder("provider_name")).append(i).toString();
									String provider_name = request.getParameter(tem_provider_name);
									String sql1 = (new StringBuilder("select * from logistics_file where provider_ID='")).append(provider_ID).append("'").toString();
									ResultSet rs1 = logistics_db.executeQuery(sql1);
									if (rs1.next())
									{
										String recommend_products = rs1.getString("recommend_products");
										if (rs1.getString("recommend_products").indexOf(product_name) == -1)
											recommend_products = (new StringBuilder(String.valueOf(recommend_products))).append(product_name).append(", ").toString();
										String sql2 = (new StringBuilder("update logistics_file set recommend_products='")).append(recommend_products).append("' where provider_ID='").append(provider_ID).append("'").toString();
										logistics_db.executeUpdate(sql2);
									}
									provider_group = (new StringBuilder(String.valueOf(provider_group))).append(provider_name).append(", ").toString();
								}

								String sql3 = (new StringBuilder("select * from design_file where product_ID='")).append(product_ID).append("'").toString();
								ResultSet rs3 = logistics_db.executeQuery(sql3);
								if (rs3.next())
								{
									String sql4 = (new StringBuilder("update design_file set provider_group='")).append(provider_group).append("' where product_ID='").append(product_ID).append("'").toString();
									logistics_db.executeUpdate(sql4);
								}
							}
						}
						catch (Exception ex)
						{
							ex.printStackTrace();
						}
						response.sendRedirect("logistics/product_providers/check_ok.jsp?finished_tag=0");
					} else
					{
						response.sendRedirect("logistics/product_providers/check_ok.jsp?finished_tag=1");
					}
				} else
				{
					response.sendRedirect("logistics/product_providers/check_ok.jsp?finished_tag=2");
				}
				logistics_db.commit();
				logistics_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
